<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <title>mybatis-generator-自动生成代码</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <style>
        .layui-form-pane .layui-form-label {
            width: 200px;
        }

        .layui-form-pane .layui-input-block {
            margin-left: 200px;
        }
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">自动生成代码</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a href="" th:href="@{/index}">首页</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">功能菜单</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" th:href="@{/index}">生成代码</a></dd>
                        <dd><a href="javascript:;" th:href="@{/list}">下载列表</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <blockquote class="layui-elem-quote layui-text" style="margin-top: 10px">
            生成代码
        </blockquote>
        <form action="" class="layui-form" lay-filter="dataBaseForm" style="position: absolute;top: 70px;left: 0px;right: 0;bottom: 50px;">

            <div style="overflow: auto;margin-bottom: 20px;position: absolute;left: 0;right: 0;top: 0;bottom: 50px;">

                <fieldset class="layui-elem-field" style="margin: 20px">
                    <legend style="color: red">数据库信息</legend>
                    <div class="layui-field-box">
                        <div class="layui-form-pane">
                            <div class="layui-form-item">
                                <label class="layui-form-label">主机</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="host" placeholder="请输入主机" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">端口</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="port" placeholder="请输入端口" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="userId" placeholder="请输入用户名" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="password" placeholder="请输入密码" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">数据库</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="database" placeholder="请输入数据库" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">表前缀</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="tablePrefix" placeholder="请输入表前缀" type="text">
                                </div>
                            </div>
                        </div>
                    </div>
                </fieldset>

                <fieldset class="layui-elem-field" style="margin: 20px">
                    <legend style="color: red">生成代码配置</legend>
                    <div class="layui-field-box">
                        <div class="layui-form-pane">
                            <div class="layui-form-item">
                                <label class="layui-form-label">实体类所在包</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="modelPackage" placeholder="请输入实体类所在包" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">mapper接口所在包</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="mapperPackage" placeholder="请输入mapper接口所在包" type="text">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">mapper映射文件所在包</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="xmlPackage" placeholder="请输入mapper映射文件所在包" type="text">
                                </div>
                            </div>
                        </div>
                    </div>
                </fieldset>

                <fieldset class="layui-elem-field" style="margin: 20px">
                    <legend style="color: red">文件夹</legend>
                    <div class="layui-field-box">
                        <div class="layui-form-pane">
                            <div class="layui-form-item">
                                <label class="layui-form-label">文件夹名称</label>
                                <div class="layui-input-block">
                                    <input autocomplete="on" class="layui-input" name="folder" placeholder="请输入文件夹名称" type="text">
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="color: red">
                            文件的生成位置：/mbg-code-folder/
                        </blockquote>
                    </div>
                </fieldset>
            </div>

            <div class="layui-form-pane" style="position: absolute;bottom: 0px;">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-filter="dataBaseSubmit" lay-submit="" type="submit">立即提交</button>
                        <button class="layui-btn layui-btn-primary" type="reset">重置</button>
                    </div>
                </div>
            </div>
        </form>


    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © mybatis-generator-自动生成代码
    </div>
</div>
<script th:src="@{layui/layui.js}"></script>
<script th:inline="javascript">

    var basicUrl = /*[[@{/dataCodeInfo/basic}]]*/ '';
    var openFolderUrl = /*[[@{/dataCodeInfo/openFolder}]]*/ '';

    //JavaScript代码区域
    layui.use(['form', 'layedit'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , $ = layui.jquery;

        form.val('dataBaseForm', {
            "host": "127.0.0.1",
            "port": "3306",
            "userId": "root",
            "password": "root",
            "database": "mbg",
            "tablePrefix": "",
            "modelPackage": "cc.bb.aa.dd.model",
            "mapperPackage": "cc.bb.aa.dd.dao",
            "xmlPackage": "mybatis.mapper",
            "folder": "mybatisCode"
        });

        //监听提交
        form.on('submit(dataBaseSubmit)', function (data) {
            console.log(JSON.stringify(data.field));

            $.ajax({
                type: "POST",
                url: basicUrl,
                data: data.field,
                success: function (result) {
                    layer.alert(result);
                }
            });
            return false;
        });


    })
</script>
</body>
</html>